﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ducu.SRV.ServiceInteface;
using Ducu.SRV.ViewModel.User;
using Ducu.BLL.Entity;
using Ducu.SRV.Query;
using Ducu.SRV.ViewModel.Chat;

namespace Ducu.SRV.ProdService
{
    public class ChatService : BaseService, IChatService
    {
        public IList<ItemModel> Get(int withUserId)
        {
            User me = getCurrentUser();
            User with = repoFactory.Load<User>(withUserId);
            var chats = repoFactory.Query<Chat>()
                .Get(me, with)
                .OrderByDescending(c => c.Id);

            IList<ItemModel> models = new List<ItemModel>();
            foreach (var item in chats)
            {
                models.Add(new ItemModel
                {
                    Content = item.Content,
                    CreateTime = item.CreateTime,
                    SaidByMe = item.From.Id == me.Id
                });
            }
            return models;
        }
    }
}
